package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

@Getter@Setter
public class TravelCommend extends BaseDomain{

    public static final Integer TYPE_WEEK = 1; //每周
    public static final Integer TYPE_MONTH = 2; //每月
    public static final Integer TYPE_STRATEGY = 3; //攻略

    private Long travelId;

    private String title;

    private String subTitle;

    private String coverUrl;

    private User author;

    private String placeName;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT + 8")
    private Date schedule;

    private Integer type = TYPE_WEEK;

    public String getJsonString(){
        HashMap map = new HashMap();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("travelId",travelId);
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String format = dateFormat.format(schedule);
        map.put("schedule",format);
        map.put("type",type);
        return JSON.toJSONString(map);
    }

    public String getTypeString(){
        String temp = null;
        if(this.type == TYPE_WEEK){
            temp = "每周推荐";
        }else if (this.type == TYPE_MONTH){
            temp = "每月推荐";
        }else if (this.type == TYPE_STRATEGY){
            temp = "攻略推荐";
        }
        return temp;
    }
}